package com.zhs.smartmall.product.service.impl;


import com.zhs.smartmall.product.model.PmsBrand;
import com.zhs.smartmall.product.dao.PmsBrandDao;
import com.zhs.smartmall.product.service.IPmsBrandService;
import com.zhs.smartmall.product.dto.PmsBrandDto;


import com.zhs.smartmallcommon.exception.ServiceException;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhs.smartmallcommon.Enum.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import cn.hutool.core.bean.BeanUtil;
import javax.annotation.Resource;
import org.springframework.transaction.annotation.Transactional;


/**
 *
 * @author zhenghuisheng
 * @since 2023-11-11
 */
@Service
@Slf4j
public class PmsBrandServiceImpl extends ServiceImpl< PmsBrandDao, PmsBrand> implements IPmsBrandService {

    @Resource
    private PmsBrandDao pmsBrandDao;

    @Override
    @Transactional
    public R addOrUpdate(PmsBrandDto pmsBrandDto) {
        if (BeanUtil.isEmpty(pmsBrandDto)) throw new ServiceException("数据不能为空");
        PmsBrand pmsBrand = new PmsBrand();
        BeanUtil.copyProperties(pmsBrandDto,pmsBrand);
        if (pmsBrandDto.getId() == null){
            pmsBrandDao.insert(pmsBrand);
            return R.ok("数据插入成功");
        }else {
            pmsBrandDao.updateById(pmsBrand);
            return R.ok("数据更新成功");
        }
    }
}